From 45b4a55ffc2f9fd9d5f63513f2f35fdeb21fbf48 Mon Sep 17 00:00:00 2001 From: Lukas Lueg Date: Thu, 21 Sep 2017 17:08:51 +0200 Subject: [PATCH] Further improve doubly-linked error-msg --- src/cargo/ops/cargo_rustc/links.rs | 36 +++++++++++------------------- tests/build-script.rs | 29 +++++++++++------------- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/links.rs b/src/cargo/ops/cargo_rustc/links.rs index 7c8d251a6..79bb240cf 100644 --- a/src/cargo/ops/cargo_rustc/links.rs +++ b/src/cargo/ops/cargo_rustc/links.rs @@ -32,37 +32,27 @@ impl<'a> Links<'a> { let describe_path = |pkgid: &PackageId| -> String { let dep_path = resolve.path_to_top(pkgid); if dep_path.is_empty() { - String::from("(This is the root-package)") + String::from("The root-package ") } else { - let mut pkg_path_desc = String::from("(Dependency via "); - let mut dep_path_iter = dep_path.into_iter().peekable(); - while let Some(dep) = dep_path_iter.next() { - write!(pkg_path_desc, "{}", dep).unwrap(); - if dep_path_iter.peek().is_some() { - pkg_path_desc.push_str(" => "); - } + let mut dep_path_desc = format!("Package `{}`\n", pkgid); + for dep in dep_path { + write!(dep_path_desc, + " ... which is depended on by `{}`\n", + dep).unwrap(); } - pkg_path_desc.push(')'); - pkg_path_desc + dep_path_desc } }; - bail!("More than one package links to native library `{}`, \ - which can only be linked once.\n\n\ - Package {} links to native library `{}`.\n\ - {}\n\ + bail!("Multiple packages link to native library `{}`. \ + A native library can be linked only once.\n\ \n\ - Package {} also links to native library `{}`.\n\ - {}\n\ + {}links to native library `{}`.\n\ \n\ - Try updating or pinning your dependencies to ensure that \ - native library `{}` is only linked once.", + {}also links to native library `{}`.", lib, - prev, lib, - describe_path(prev), - pkg, lib, - describe_path(pkg), - lib) + describe_path(prev), lib, + describe_path(pkg), lib) } if !unit.pkg.manifest().targets().iter().any(|t| t.is_custom_build()) { bail!("package `{}` specifies that it links to `{}` but does not \ diff --git a/tests/build-script.rs b/tests/build-script.rs index fd0dc9550..4e7a5816f 100644 --- a/tests/build-script.rs +++ b/tests/build-script.rs @@ -248,16 +248,14 @@ fn links_duplicates() { assert_that(p.cargo_process("build"), execs().with_status(101) .with_stderr("\ -error: More than one package links to native library `a`, which can only be \ -linked once. +[ERROR] Multiple packages link to native library `a`. A native library can be \ +linked only once. -Package foo v0.5.0 (file://[..]) links to native library `a`. -(This is the root-package) +The root-package links to native library `a`. -Package a-sys v0.5.0 (file://[..]) also links to native library `a`. -(Dependency via foo v0.5.0 (file://[..])) - -Try updating[..] +Package `a-sys v0.5.0 (file://[..])` + ... which is depended on by `foo v0.5.0 (file://[..])` +also links to native library `a`. ")); } @@ -303,16 +301,15 @@ fn links_duplicates_deep_dependency() { assert_that(p.cargo_process("build"), execs().with_status(101) .with_stderr("\ -error: More than one package links to native library `a`, which can only be \ -linked once. - -Package foo v0.5.0 (file://[..]) links to native library `a`. -(This is the root-package) +[ERROR] Multiple packages link to native library `a`. A native library can be \ +linked only once. -Package a-sys v0.5.0 (file://[..]) also links to native library `a`. -(Dependency via a v0.5.0 (file://[..]) => foo v0.5.0 (file://[..])) +The root-package links to native library `a`. -Try updating[..] +Package `a-sys v0.5.0 (file://[..])` + ... which is depended on by `a v0.5.0 (file://[..])` + ... which is depended on by `foo v0.5.0 (file://[..])` +also links to native library `a`. ")); } -- 2.30.2